﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win.Model;

namespace Win.DAL
{
    public class ManegerDAL
    {
        DbContext dbContext = new exp03dbEntities1();

        public List<ManagerInfo> GetManegerList()
        {
            DbSet<ManagerInfo> managers = dbContext.Set<ManagerInfo>();
            List<ManagerInfo> managerInfos = new List<ManagerInfo>(managers);
            return managerInfos;
        }

        public ManagerInfo GetManagerById(int id)
        {
            ManagerInfo manager = dbContext.Set<ManagerInfo>().Where(u => u.MId.Equals(id)).FirstOrDefault();
            return manager;
        }

        public void SetManager(ManagerInfo manager)
        {
            dbContext.Entry<ManagerInfo>(manager).State = EntityState.Added;
            dbContext.SaveChanges();
        }

        public void DeleteManagerById(int id)
        {
            ManagerInfo manager = GetManagerById(id);
            dbContext.Entry<ManagerInfo>(manager).State = EntityState.Deleted;
            dbContext.SaveChanges();
        }
    }
}
